<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
* showReps.html
* List of available report templates based on Smarty
*
* @version 2011.0812
* @author: Artem Osmakov
*
* @copyright (C) 2005-2011 University of Sydney Digital Innovation Unit.
* @link: http://HeuristScholar.org
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Heurist academic knowledge management system
* @todo
**/

-->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>

<!-- yui layout -->

<!--<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/reset-fonts-grids/reset-fonts-grids.css">
-->
<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/container/assets/skins/sam/container.css">

<!-- Skin CSS files resize.css must load before layout.css -->
<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/assets/skins/sam/resize.css">
<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/assets/skins/sam/layout.css">
<!-- Utility Dependencies -->
<script src="../../external/yui/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="../../external/yui/2.8.2r1/build/dragdrop/dragdrop-min.js"></script>
<script src="../../external/yui/2.8.2r1/build/element/element-min.js"></script>
<!-- Optional Animation Support
<script src="../../external/yui/2.8.2r1/build/animation/animation-min.js"></script> -->
<!-- Optional Resize Support -->
<script src="../../external/yui/2.8.2r1/build/resize/resize-min.js"></script>
<!-- Source file for the Layout Manager -->
<script src="../../external/yui/2.8.2r1/build/layout/layout-min.js"></script>

<!-- TREEVIEW DEFS -->
<!-- Required CSS -->
<link type="text/css" rel="stylesheet" href="../../external/yui/2.8.2r1/build/treeview/assets/skins/sam/treeview.css">
<!-- Optional dependency source file -->
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/animation/animation-min.js"></script>
<!-- Optional dependency source file to decode contents of yuiConfig markup attribute-->
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/json/json-min.js" ></script>
<!-- TreeView source file -->
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/treeview/treeview-min.js" ></script>
<!-- END TREEVIEW DEFS-->
<!-- for yui simply dialog -->
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/container/container-min.js"></script>
<script type="text/javascript" src="../../external/jquery/jquery.js"></script>
<!--
<script type="text/javascript" src="../../external/tinymce3.4.4/jscripts/tiny_mce/tiny_mce.js"></script>
<script src="../../external/js/ace/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
-->

<link rel="stylesheet" type="text/css" href="../../common/css/global.css">
<link rel="stylesheet" type="text/css" href="../../common/css/report.css">

<script src="../../external/js/codemirror-2.35/lib/codemirror.js"></script>
<link rel="stylesheet" href="../../external/js/codemirror-2.35/lib/codemirror.css">
<script src="../../external/js/codemirror-2.35/mode/smarty/smarty.js"></script>

<style type="text/css">
/* hide header in top layout */
.yui-skin-sam .yui-layout .yui-layout-hd {
	background: none;
	border: 1px solid #ff0000;
	display: none;
	height: 0px;
}
/*display: none !important;
	display: block;
*/
.linkadmin {
	visibility: hidden;
}
#editor, .CodeMirror {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
/*   	border: 1px solid #7D9AAA;
	height: 100%;
	width: 100%;
*/}
.CodeMirror *{
  font-family: Courier, Monospace !important;
  font-size: 14px;
}
</style>
<script type="text/javascript">
			var showReps, isEditorVisible=false;
</script>
</head>

<body class="yui-skin-sam"  onresize="onResize()">
<script type="text/javascript" src="../../common/js/utilsLoad.js"></script>
<script type="text/javascript" src="../../common/js/utilsUI.js"></script>
<script type="text/javascript" src="../../viewers/smarty/showReps.js"></script>

<iframe id="ifrmPrint" src="#" style="width:0px; height:0px;"></iframe>

<!-- position:absolute;top:30px;height:30px;

	style="position:absolute;top:25px;bottom:0px;left:0px;right:0px;"
		<div id="layout"></div>
-->

<div id="viewercontainer">
	<div id="toolbardiv" style="width:100%;height:30px;">
		<div style="padding:5px;display:inline-block;">
			<select id="cbUseAllRecords1" onChange="setQueryMode(event)" style="width:90px">
				<option value="all" selected="selected">All on page</option>
				<option value="selected">Selected only</option>
				<option value="main">Query result</option>
			</select>
		</div>
		<label style="width:100px;padding-left:5px;white-space:nowrap;">Select template:</label>
		<select id="selTemplates" onChange="onSelectTemplate()" style="display:inline-block;width:200px;margin-right:100px"></select>

		<span id="recordCount"></span>

		<ul id="rep_list" class="horizontal menu">
			<li style="width:130px;"><span class="button">Menu</span>
				<ul id="toolMenuItems">
				</ul>
			</li>
		</ul>

	</div>
	<div id="rep_container"></div>
</div>
<div id="editorcontainer" style="display:none">
	<h2>Template <span id="edTemplateName"></span></h2>
	<div id="templateCode">
		<!-- PLAIN MODE <textarea id="edTemplateBody" name="edTemplateBody"></textarea>
		<div id="editor"></div>-->
	</div>
	<div id="templateTree">
		<div style="margin-bottom: 20px;white-space:nowrap"> <span style="white-space:normal">Position cursor in text on left before selecting actions below<br/>
			</span>
			<div><label>Modifiers</label>
			<select id="selInsertModifiers" onChange="onSelectModifier()" style="width:100px">
				<option>choose modifier</option>
				<option>capitalize</option>
				<option>cat</option>
				<option>count_characters</option>
				<option>count_paragraphs</option>
				<option>count_sentences</option>
				<option>count_words</option>
				<option>date_format</option>
				<option>default</option>
				<option>escape</option>
				<option>indent</option>
				<option>lower</option>
				<option>nl2br</option>
				<option>regex_replace</option>
				<option>replace</option>
				<option>spacify</option>
				<option>string_format</option>
				<option>strip</option>
				<option>strip_tags</option>
				<option>truncate</option>
				<option>upper</option>
				<option>wordwrap</option>
			</select></div>
			<div><label>Style</label>
			<select id="selInsertMode" style="width:100px">
				<option value="0">Field only</option>
				<option value="1">Field + Label</option>
				<option value="2">Field + function wrapper</option>
			</select></div>
			<div><label>Insert</label><a href="javascript:void(0)" title="ForEach loop to loop through all records in the current query or selection" onClick="showReps.insertRootForEach()">Records loop</a><br>
			</div>
			<div><label></label><a href="../../help/smarty_reports.html" title="Read full documentation on the Smarty templating language" target="_blank">Smarty Help</a></div>
		</div>
		<div id="treeContainer">
			<div id="varsTree" class="ygtv"></div>
			<!-- was ygtv-checkbox -highlight -->
		</div>
	</div>
	<div class="actionButtons">
		<button onClick="doExecuteFromEditor()" title="Test your template" style="font-size:1.1em;">TEST</button>
		&nbsp;
		<div style="display:inline-block;">
			<select id="cbErrorReportLevel">
				<option value="0" selected="selected">Ignore errors</option>
				<option value="1">Show warnings</option>
				<option value="2">Show errors</option>
				<option value="3">Debug info</option>
			</select>
			<select id="cbUseAllRecords2" onChange="setQueryMode(event)" style="width:90px">
				<option value="all" selected="selected">All on page</option>
				<option value="selected">Selected only</option>
				<option value="main">Query result</option>
			</select>
		</div>
		<button onClick="doEditor(2)" title="Save, Close and Execute the updated template">Save</button>
		<button onClick="doEditor(1)">Save As</button>
		<!--		<button onClick="doEditor(3)">Delete</button>
-->
		<button onClick="doEditor(0)">Close Editor</button>
	</div>

	<!--
					<select id="selRectype" onchange="window.showReps.onSelectRectype()" title="List of available rectypes">
							<option>List of available rectypes</option>
					</select>
					<button onclick="window.showReps.clearAllSeelectionInTree()">Clear marked</button>
					<div  style="padding-right:10px;">
						<button onclick="doEditor(0)">Close Editor</button>
					 button onclick="javascript:setupMCE();">TinyMCE</button
					</div>
-->

</div>
<script type="text/javascript">

var isInited = false;
function setupMCE() {
if(isInited){
   tinyMCE.execCommand('mceToggleEditor',false,'edTemplateBody');
   isEditorVisible = !isEditorVisible;
}else{
   tinyMCE.init({
      mode : "textareas",
      theme : "advanced",
      editor_selector : "mceAdvanced",
/*"advanced"
      plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

      theme_advanced_buttons1 : "bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,sub,sup,|,charmap,emotions",
      theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,|,insertdate,inserttime",
      theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid", //",iespell,media,advhr",
*/
/*
      theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
      theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
      theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
      theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
*/
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_statusbar_location : "bottom",
      theme_advanced_resizing : true
   });
   isInited = true;
   isEditorVisible = true;
}

}

	//
	function onPrint()
	{
		try{
			var oIframe = document.getElementById("ifrmPrint");
			var oContent = document.getElementById("rep_container").innerHTML;
			var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
			if (oDoc.document) oDoc = oDoc.document;
			oDoc.write("<head><title></title>");
			oDoc.write("</head><body onload=\"this.focus(); this.print();\">");
			oDoc.write(oContent + "</body>");
			oDoc.close();
		}
		catch(e){
			//self.print();
		}
	}

	//
	function onFile(){

		var sel = document.getElementById('selTemplates');
		if(Hul.isnull(sel) || Hul.isnull(sel.options) || sel.options.length===0) { return; }

		var template_file = sel.options[sel.selectedIndex].value; // by default first entry

		Hul.popupURL(this,'../viewers/smarty/repMenu.html?template_file='+template_file,null);

/* OLD WAY
		var surl = top.HEURIST.baseURL + "viewers/smarty/showReps.php?"+
				window.showReps.getQuery() + '&publish=1&debug=0&template='+template_file;

		window.prompt (
"                                         Copy to clipboard by hitting Ctrl-C or [Enter]\n\n"+
"                Note: The URL will only show records to which the viewer has access.\n"+
"External viewers will not be able to see any records unless they are marked as Public visibility\n\n", surl);
*/
	}

	//
	function onShowEditor()
	{
		var sel = document.getElementById('selTemplates');

		if(sel.selectedIndex>=0){
			var template_file = sel.options[sel.selectedIndex].value;
			window.showReps.showEditor(template_file);
		}
	}

	//
	function onDeleteTemplate()
	{
		var sel = document.getElementById('selTemplates');

		if(sel.selectedIndex>=0){
			window.showReps.originalFileName(sel.options[sel.selectedIndex].value);
			doEditor(3);
		}
	}

	//
	function onPublish()
	{
		var sel = document.getElementById('selTemplates');

		if(sel.selectedIndex>=0){
			window.showReps.onPublish(sel.options[sel.selectedIndex].value);
		}
	}


	//
	//
	function onGenerate()
	{
		if(window.showReps.isNeedSelection()){
			alert('You have to select some records');
		}else{
		var name=jQuery.trim(prompt("Please enter template name",""));
		if (!Hul.isempty(name))
		{
			window.showReps.generateTemplate(name);
		}
	}
	}

	//
	function doExecuteFromEditor()
	{
		window.showReps.doExecuteFromEditor();
	}

	//
	function doEditor(action)
	{
		window.showReps.operationEditor(action);
	}

	//
	function onSelectTemplate()
	{
		var sel = document.getElementById('selTemplates');
		if(sel.selectedIndex>=0){

			var template_file = sel.options[sel.selectedIndex].value;

			top.HEURIST.util.setDisplayPreference("viewerCurrentTemplate", template_file);
			window.showReps.processTemplate(template_file);
		}
	}

	function onSelectModifier(){
		var sel = document.getElementById('selInsertModifiers');
		if(sel.selectedIndex>0){
			window.showReps.insertModifier(sel.value);
			sel.selectedIndex = 0;
		}
	}

	function setQueryMode(event,needReload){
		var elem = event.target;
		window.showReps.setQueryMode(elem.value);
	}

	function onResize(){
		window.showReps.onResize(this.innerWidth);
	}

	//
	//  starts initialization on load completion of this window
	function loadHandler(){
		window.showReps = new ShowReps();

		window.showReps.onResize(this.innerWidth);
		//setupMCE();

		//$('.linkadmin').css('display', 'block  !important');
		//$('.linkadmin').css('display', 'none  !important');
		//$('#lnkDel').css('display', 'none  !important');
		//$('.linkadmin').css('visibility', 'visible');


		var s = '<li><a href="#" onClick="onSelectTemplate()">Reload</a></li><li><a href="#" onClick="onPrint()">Print</a></li>'+
		'<li><a href="#" onClick="onFile()">Get URL</a></li>';

		if(top.HEURIST.is_logged_in()){
			s = s + '<li><a href="#" onClick="onPublish()">Publish</a></li>';

			if(top.HEURIST.user.isInWorkgroup(1) || top.HEURIST.is_wgAdmin(null)){ //is_admin()){
				s = s + '<li><a href="#" onClick="onDeleteTemplate()">Delete Template</a></li>'+
				'<li><a href="#" onClick="onShowEditor()">Edit Template</a></li>'+
				'<li><a href="#" onClick="onGenerate()">New Template</a></li>';
			}
		}

		var elem = document.getElementById('toolMenuItems');
		elem.innerHTML = s;
	}

	YAHOO.util.Event.addListener(window, "load", loadHandler );

</script>
</body>
</html>
